In the context of computer software, an application programming interface (API) specifies how two or more applications communicate with one another. APIs are very common in today's software, allowing otherwise heterogeneous objects or applications to interact, utilize each other's functionality and to generally be compatible with each other. In a typical scenario, one application invokes the functionality of another application by making a call against that application's API, which it exposes.
APIs can generally be divided into synchronous APIs and asynchronous APIs. Synchronous APIs block the caller of the API until a result of the call is returned to the caller. This results in the caller having to wait for the result before proceeding with other processing. Asynchronous APIs, on the other hand, return immediately and the actual status is returned at the end after the API completion through a callback or can be polled periodically by the caller, depending on the API implementation.
Both synchronous and asynchronous APIs can be useful and have applicability in different areas. For example, asynchronous APIs can be useful in cases where the task performed takes more time than is required for the caller to wait. The application utilizing asynchronous APIs would typically need to follow certain programming techniques to support asynchronous APIs. Synchronous APIs should generally be faster than asynchronous and the majority of APIs tend to be synchronous. There is no absolute rule to specify which type of API is the most suitable since it often depends on the context and scale of the environment. A thorough analysis should be performed to decide upon which type of API to implement for the particular environment at hand.
There are many cases when developers select the wrong or less-optimal types of API in their implementation. For example, some developers simply utilize synchronous APIs due to unseen scenarios, lack of foresight and the like. Furthermore, especially in large scale environments, synchronous APIs may block callers due to various factors such as system slowdowns, larger than expected data sizes and others. Some applications end up using many third-party modules or APIs, over which the developer has no control. Some of these third party APIs may be well written to handle all use cases, while others may not. If the third party API was not written correctly, the calling application may end up waiting indefinitely for the synchronous API and since the calling application has no control over the third party code, such problems are often difficult to resolve.